<template>
  <div class="main-bg">
    <div class="report-list" v-loading="loading">
      <div
        class="report-list-item"
        v-for="item in list"
        :key="item.id"
        @click="toDetail(item)"
      >
        <div class="report-list-item-header" style="cursor: pointer">
          <img
            class="report-list-item-header-icon"
            v-if="item.item_type == 3"
            src="@/assets/images/pdf-icon.png"
          />
          <span>{{ item.name }}</span>
        </div>
        <div class="report-list-item-info">
          <div class="report-list-item-info-list" v-if="item.item_type == 3">
            <img
              class="report-list-item-info-list-new"
              src="@/assets/images/new.png"
              v-if="item.is_new == 1"
              alt=""
            />
            <!-- <div class="report-list-item-info-list-read">{{item.read_count}}人阅读</div> -->
            <div class="report-list-item-info-list-date">
              上传于{{ item.timeText }}
            </div>
            <div class="report-list-item-info-list-page">
              {{ item.page_count }}页
            </div>
            <div class="report-list-item-info-list-chat">
              {{ item.idea_count }}个图表
            </div>
          </div>
          <div class="report-list-item-info-list" v-if="item.item_type == 2">
            <div class="report-list-item-info-list-read">文件夹</div>
            <div class="report-list-item-info-list-page">
              {{ item.page_count }}份文档
            </div>
            <div class="report-list-item-info-list-date">
              创建于{{ item.timeText }}
            </div>
          </div>
          <div class="report-list-item-info-action">
            <!-- <img
              class="report-list-item-info-action-item"
              @click.stop="share(item)"
              src="@/assets/images/icon-phone.png"
            />
            <img
              class="report-list-item-info-action-item"
              @click.stop="share(item)"
              src="@/assets/images/icon-share.png"
            /> -->
            <add-group :id="item.id" v-if="item.item_type == 3"></add-group>
          </div>
        </div>
        <div
          class="report-list-item-img"
          v-if="item.chart_list && item.chart_list.length != 0"
        >
          <div
            class="report-list-item-img-item"
            v-for="(chart, chartIndex) in item.chart_list"
            :key="chartIndex"
          >
            <img
              :src="chart.online_url"
              alt=""
              @click.stop="lookChat(chart, item, chartIndex)"
            />
          </div>
        </div>
      </div>
      <div class="report-page">
        <el-pagination
          background
          layout="prev, pager, next"
          :page-size.sync="currentPageSize"
          :current-page.sync="data.page"
          :total="listTotal"
          @current-change="pageChange"
        >
        </el-pagination>
      </div>
    </div>

    <share v-model="shareModal" :fid="shareFid"></share>
  </div>
</template>

<script>
import storage from "@/utils/storage";
import { myUploadFile } from "@/api/login.js";
import { mapGetters } from "vuex";
import { shareFile } from "@/api/share.js";
import addGroup from "@/components/addGroup.vue";
import share from "@/components/share.vue";
export default {
  data() {
    return {
      shareModal: false,
      shareFid: "",
      data: {
        sid: "",
        page: 1,
      },
      listTotal: 0,
      list: [],
      currentPageSize: 15,
      infoImg: "",
      infoImgList: [],
      chatName: "",
      listIndex: 0,
      loading: false,
    };
  },
  components: { addGroup, share },
  created() {
    if (process.client) {
      this.data.sid = this.sid;
      this.getData();
    }
  },
  computed: {
    ...mapGetters(["sid"]),
  },
  methods: {
    getData() {
      this.loading = true;
      myUploadFile(this.data).then((res) => {
        this.list = res.infor.items;
        this.listTotal = res.infor.total_count;
        this.currentPageSize = res.infor.page_size;
        this.loading = false;
        // console.log(res);
      });
    },
    share(item) {
      this.shareFid = item.fid || item.id;
      this.shareModal = true;
    },
    pageChange(page) {
      this.data.page = page;
      this.getData();
    },
    toDetail(item) {
      let { href } = this.$router.resolve({
        path: "/detail?fid=" + item.id,
      });
      if (process.client) {
        window.open(href, "_blank");
      }
    },
    lookChat(info, item, index) {
      this.infoImg = info.online_url;
      this.infoImgList = item.chart_list;
      this.chatName = item.name;
      this.listIndex = index;
    },
  },
};
</script>

<style lang='less' scoped>
.main-bg {
  width: 1000px;
  margin: 0 auto;
  padding-top: 20px;
  margin-top: 54px;
}
.box-card {
  width: 480px;
  margin-top: 20px;
}
.text {
  font-weight: 600;
  font-size: 20px;
}
.text-mini {
  font-size: 14px;
}
.report {
  width: 720px;
  margin: 0 auto;
  min-height: 500px;
  &-search {
    margin: 40px 0;
    /deep/ .el-input-group__append {
      background: #467dd0;
      color: #fff;
      width: 96px;
    }
  }
  &-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    &-title {
      font-size: 16px;
      color: #3f4750;
      cursor: pointer;
      // font-weight: bold;
    }
    &-tag {
      &-item {
        margin-left: 8px;
      }
    }
  }
  &-list {
    position: relative;
    display: flex;
    justify-content: flex-start;
    align-items: stretch;
    flex-wrap: wrap;
    padding-top: 14px;
    padding-bottom: 20px;
    &-item {
      padding: 16px 20px 16px;
      width: 100%;
      background: #fff;
      border-radius: 2px;
      border: 1px solid rgba(233, 235, 238, 1);
      margin-top: 12px;
      &-header {
        display: flex;
        justify-content: flex-start;
        align-items: flex-start;
        font-size: 16px;
        line-height: 22px;
        &-icon {
          width: 16px;
          height: 16px;
          display: block;
          margin-top: 4px;
          margin-right: 6px;
        }
      }
      &-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 15px;
        &-list {
          display: flex;
          justify-content: flex-start;
          align-items: center;
          font-size: 14px;
          color: #8e969d;
          &-new {
            height: 24px;
            display: block;
            margin-right: 5px;
            width: 24px;
          }
          &-read,
          &-date,
          &-page,
          &-chat {
            margin-right: 20px;
          }
        }
        &-action {
          display: flex;
          justify-content: flex-end;
          align-items: center;
          &-item {
            width: 24px;
            height: 24px;
            display: block;
            margin-left: 16px;
          }
        }
      }
      &-img {
        margin-top: 19px;
        display: flex;
        justify-items: flex-start;
        align-items: center;
        &-item {
          width: 163px;
          height: 163px;
          display: block;
          margin-left: 12px;
          border-radius: 2px;
          display: flex;
          justify-items: center;
          align-items: center;
          &:first-child {
            margin-left: 0;
          }
          img {
            max-width: 100%;
            max-height: 100%;
            display: block;
          }
        }
      }
    }
  }
  &-page {
    width: 100%;
    padding: 15px 0;
    text-align: center;
  }
}
</style>
